package com.lsu.app;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lsu.app.bean.*;
import com.lsu.app.service.*;
import com.lsu.app.tool.AESUtil;
import com.lsu.app.tool.jiebaUtil;
import com.lsu.app.tool.uploadUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.List;

/**
 * @author hjj
 * @date 2023/10/22 15:36
 */
@SpringBootTest
public class test {
    @Value("${web.upload-path}")
    private String uploadPath;

    @Autowired
    private KindService kindService;
    @Autowired
    private CourseService courseService;
    @Autowired
    private ClickDateService clickDateService;
    @Autowired
    private CourseScoreService scoreService;
    @Autowired
    private ScheduleService scheduleService;
    @Autowired
    private ScheduleCourseService scheduleCourseService;
    @Autowired
    private TimeTableService timeService;
    @Test
    void testmo(){
        String str = "sdad.jsp";
        System.out.println(str.substring(0,str.lastIndexOf(".")));
    }
    @Test
    void addSc(){
        Schedule schedule  = new Schedule("",7,"小胡测试课程表",LocalDateTime.now().toString(),"2023-11-11",1,15,1,1);
        scheduleService.save(schedule);
        List<Integer> courseIds = courseService.getCourseIds();
        //设置默认课程节数以及时间
        String[] startTime = {"08:00:00","9:45:00","14:00:00","15:45:00","18:40:00"};
        String[] endTime = {"9:30:00","12:15:00","15:30:00","17:15:00","20:10:00"};
        for(int i=1;i<=5;i++){
            TimeTable timeTable = new TimeTable(schedule.getId(),i,endTime[i-1],startTime[i-1]);
            timeService.save(timeTable);
            for (int j=1;j<=7;j++){
                Random random = new Random();
                int ind = random.nextInt(courseIds.size());
                int aa = ind%3;
                ScheduleCourse sc = new ScheduleCourse(schedule.getId(),j,i,aa==1?courseIds.get(ind):0,1,16,1,ind%2);
                scheduleCourseService.save(sc);
            }
        }
    }
    @Test
    void addScore(){
        List<Integer> courseIds = courseService.getCourseIds();
        int[] ids = {3,4,5,7,27,31,32,33,34};
        int i=0;
        while (i++<200){
            Random rand = new Random();
            int count = rand.nextInt(ids.length);
            int index = rand.nextInt(courseIds.size());
            int score = rand.nextInt(5);
            scoreService.save(new CourseScore(courseIds.get(index),ids[count],score, LocalDateTime.now().toString()));
        }
    }
    @Test
    void addClick(){
        List<Integer> courseIds = courseService.getCourseIds();
        for (Integer courseId : courseIds) {
            Random rand = new Random();
            if (rand.nextInt(10)%2==0){
                for (int i=0;i<30;i++){
                    int count = rand.nextInt(100);
                    clickDateService.save(new ClickDate(courseId,count,LocalDate.now().plusDays(-i).toString(),courseService.getTeacherIdByCourseId(courseId)));
                        courseService.addClickByIdOfCount(courseId,count);
                }
            }
        }

    }
    @Test
    void testDefaultImg(){
        uploadUtil.defaultImgByString("jsp",uploadPath,"test");
    }//图片生成类
    @Test
    void testsort(){
        Map<String,Integer> map = new HashMap<>();
        map.put("hjj",5);
        map.put("xlj",3);
        map.put("zl",4);
        map.put("ym",6);
        map.put("zzm",1);
        System.out.println("排序前：");
        System.out.println(map);
        System.out.println("排序后：");
        System.out.println(AESUtil.sortDescend(map));
        System.out.println("提取成list");
        System.out.println(new ArrayList<>(AESUtil.sortDescend(map).keySet()));
    }
    @Test
    void testapi(){
            int weekly = 15;
            String startDate= "2023-11-00";
            try{
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                Date date = sdf.parse(startDate);
                Date now = Date.from(LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant());//当前日期
                if(date.after(now)){ //未到开始周
                    System.out.println("未到开始周");
                }else {
                    int days = (int) ((now.getTime()-date.getTime())/(24*60*60*1000));
                    if((days/7)+1<weekly){
                        System.out.println((days/7)+1);
                    }else{
                        System.out.println(0);
                    }

                }
            }catch (ParseException e){
                System.out.println(e.getMessage());
            }
    }
    @Test
    void addLink(){

//        Integer[][] data = new Integer[][]{
//                {56,57, 58, 59, 60, 61, 3, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 23, 24, 26, 27, 28, 29, 30, 31, 32, 37, 38, 40, 42, 45,46},
//                {1,56,57,58,59,60,61,4,35,36,7,8,9,10,11,12,13,14,15,16,17,18,21,23,24,26,27,28,29,30,31,32,37,38,40,42},
//                {1,56,57,58,59,60,61,7,8,9,10,11,12,13,14,15,17,18,20,21,22,23,24,26,27,28,29,30,31,32,33,37,38,40},
//                {1,56,57,58,59,60,61,7,8,9,10,11,12,13,14,15,17,18,22,23,24,26,27,28,29,30,31,32,33,38,40,41,43,46},
//                {1,56,57,58,59,60,61,6,7,8,9,10,11,12,13,14,15,17,18,20,21,30,31,32,33,38,39,40,41,43},
//                {1,56,57,58,59,60,61,7,8,17,18,20,21,22,24,31,32,33,37,38,39,40,41,42,43,44,47,48,49,50,51,52,53,54},
//                {1,56,57,58,59,60,61,6,7,9,10,11,12,13,14,15,16,17,18,20,31,32,33,38,39,40,41,42,43,44,47,48,49,50,51,52,53,54},
//                {1,56,57,58,59,60,61,7,8,17,18,22,23,24,26,27,28,29,30,32,33,37,38,40,41,44,47,48,49,50,51,52},
//                {1,56,57,58,59,60,61,7,8,9,10,11,12,13,14,15,18,22,24,26,27,28,29,30,32,37,38,40,41},
//                {1,56,57,58,59,60,61,3,4,35,36,7,8,16,21,25,26,27,28,29,30,31,32,33,37,38,40},
//                {1,56,57,58,59,60,61,2,62,63,64,65,6,17,20,21,32,33,38},
//                {1,56,57,58,59,60,61,4,35,36,5,8,17,21,23,26,27,28,29,30,31,32,38,40},
//                {1,56,57,58,59,60,61,7,8,17,18,21,22,23,24,32,33,37,38,39,40,42},
//                {1,56,57,58,59,60,61,17,18,19,23,25,26,27,28,29,30,31,32,4,35,36,34,38,39,55},
//        };
//
//        for (int i=0;i<data.length;i++){
//            for (int j=0;j<data[i].length;j++){
//                if(data[i][j]!=null){
//                    kindService.insertTasteKind(i+1,data[i][j]);
//                }
//            }
//        }


    }
}
